<%@page import="com.etc.zzsys.service.impl.QuestionServiceimpl"%>
<%@page import="com.etc.zzsys.service.QuestionService"%>
<%@page import="com.etc.zzsys.entity.Question"%>
<%@page import="com.etc.zzsys.service.UserService"%>
<%@page import="com.etc.zzsys.service.impl.UserServiceImpl"%>
<%@page import="com.etc.zzsys.entity.User"%>
<%@page import="java.util.List"%>
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">

<title>问答系统后台</title>

<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="css/dashboard.css" rel="stylesheet">
<!-- layui css -->
<link rel="stylesheet" href="layui/css/layui.css" media="all">
</head>

<body>

	<nav class="navbar navbar-inverse navbar-fixed-top">
	<div class="container-fluid">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed"
				data-toggle="collapse" data-target="#navbar" aria-expanded="false"
				aria-controls="navbar">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="#">问答系统后台</a>
		</div>
		<div id="navbar" class="navbar-collapse collapse">
			<ul class="nav navbar-nav navbar-right">
				<li><a href="#">仪表盘</a></li>
				<li><a href="#">设置</a></li>
				<li><a href="#">帮助</a></li>
			</ul>
			<form class="navbar-form navbar-right" method="post"
				action="ps?op=querylist">
				<input type="text" class="form-control" id="key" value="${key }"
					name="key" placeholder="搜索...">
				<button class="btn btn-default" type="submit">搜索</button>
			</form>
		</div>
	</div>
	</nav>

	<div class="container-fluid">
		<div class="row">
			<div class="col-sm-3 col-md-2 sidebar">
				<ul class="nav nav-sidebar">
					<li><a href="index.jsp">首页<span class="sr-only">(current)</span></a>
					</li>
					<li><a href="Userservlet?op=list">用户列表</a></li>
					<li><a href="addUsers.jsp">新增用户</a></li>
					<li><a href="#">Export</a></li>
				</ul>
				<ul class="nav nav-sidebar">
					<li class="active"><a href="qs?op=querylist">问题列表</a></li>
					<li><a href="qs?op=add">提出问题</a></li>
					<li><a href="">One more nav</a></li>
					<li><a href="">Another nav item</a></li>
					<li><a href="">More navigation</a></li>
				</ul>
				<ul class="nav nav-sidebar">
					<li><a href="as.do?op=query">答案管理</a></li>
					<li><a href="">One more nav</a></li>
					<li><a href="">Another nav item</a></li>
				</ul>
			</div>



			<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
				<h2 class="sub-header">用户信息</h2>
				<div class="table-responsive">
					<table class="table table-striped">
						<thead>
							<tr>
								<th>编号</th>
								<th>标题</th>
								<th>内容</th>
								<th>提问时间</th>
								<th>用户姓名</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
						<c:if test="${pdata.data==null}">
							<% response.sendRedirect("qs?op=querylist"); %>
						</c:if>
				
							<c:forEach items="${pdata.data }" var="q">
								<tr>
									<td>${q.qid}</td>
									<td>${q.title}</td>
									<td>${q.content}</td>
									<td>${q.qdate}</td>
									<td>${q.userName}</td>
									<td class="col-md-2"><button
											class="btn btn-default btn_update" value="${q.qid}"
											data-toggle="modal" data-target="#myModal2">修改</button> <a
										class="btn btn-danger btn_del">删除</a></td>
								</tr>
							</c:forEach>

						</tbody>
					</table>
				</div>

				<!-- layui分页 -->
					<div style="text-align:center;" id="layuiPage"></div>
			</div>
		</div>
	</div>


	<!-- Modal -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改问题</h4>
				</div>
				<div class="modal-body">
					<iframe name="myframe" style="border: 0px;" width="100%"
						height="600px" id="myframe" border="none"></iframe>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				</div>
			</div>
		</div>
	</div>


	<!-- Modal -->
	<div class="modal fade" id="myModal2" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改问题</h4>
				</div>
				<div class="modal-body">
					<!-- 表单开始 -->
					<form class="form-horizontal" role="form" action="qs?op=doAdd"
						method="post">
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">标题</label>
							<div class="col-sm-8">
								<input type="text" required="required" class="form-control"
									name="title" id="title" value="" />
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">内容</label>
							<div class="col-sm-6">
								<textarea name="content" id="content" required="required"
									rows="12" class="form-control"></textarea>
							</div>
						</div>

						<div class="form-group">
							<label for="" class="col-sm-2 control-label">用户名</label>
							<div class="col-sm-3">
								<select class="form-control" name="userId" id="userId">
									<option>请选择</option>
									<c:forEach items="${ulist }" var="u"></c:forEach>
									<option value="${u.userId }">${u.userName }</option>
								</select>
							</div>
						</div>


						<div class="form-group">
							<div class="col-sm-offset-2 col-sm-10">
								<button type="submit" class="btn btn-danger">提交</button>
							</div>
						</div>
					</form>
					<!-- 表单结束 -->
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				</div>
			</div>
		</div>
	</div>
	<!-- Bootstrap core JavaScript
    ================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="js/jquery-3.3.1.js"></script>
	<script src="js/bootstrap.min.js"></script>

	<script>
		$(function() {

			$(".btn_del").click(
					function() {
						var cfr = confirm("是否确认要删除？");
						if (cfr) {
							location.href = "qs?op=del&qId="
									+ $(this).parents("tr").find("td").eq(0)
											.text() + "";
						}
					});

			$(".btn_update").click(function() {
				//myframe.location.href="qs?op=updateDetail&id="+$(this).val()+"";
				var title = $(this).parents("tr").find("td").eq(1).text();
				var content = $(this).parents("tr").find("td").eq(2).text();
				console.log(userId);
				$("#title").val(title);
				$("#content").val(content);
			});
		});
	</script>
	
	<!-- layui js -->
	<script src="layui/layui.js" charset="utf-8"></script>
	<script>
layui.use(['laypage', 'layer'], function(){
  var laypage = layui.laypage
  ,layer = layui.layer;
  

  //完整功能
  laypage.render({
    elem: 'layuiPage'
    ,count: ${pdata.total}
  	,limit:${pdata.pageSize}
  	,limits:[1,2,3]
  	,curr:${pdata.page}
  	,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
    ,jump: function(obj,first){
     if(!first){
    	location.href="qs?op=querylist&pageSize="+obj.limit+"&page="+obj.curr+"&key="+document.getElementById("key").value;
     }
    }
  });

  
});
</script>
</body>

</html>